<extend name="Base/common"/>
<block name="body">
	<div class="mui-content div_lucky_code">
		<div>幸运数字：</div>
		<div class="lucky_code">{$code}</div>
	</div>
	
    <div class="user_info">
		<div class="mui-pull-left">发起人：</div>
		<div class="mui-pull-left user_avator">
    		<if condition="get_avatar($snatch_info['uid']) eq ''">
    		<img src="__IMG__/default.jpg">
    		<else />
    		<img src="{$snatch_info.uid|get_avatar}"/>
    		</if>
		</div>
		<div class="mui-pull-left">
		<gt name="snatch_info.uid" value="0">
		{$snatch_info.uid|get_nickname|substr_cut}
		<else />
		(管理员)
		</gt>
		</div>
    </div>
    <div class="join_info mui-row">
    	<div class="mui-col-xs-5">
    		<eq name="$snatch_info.pic" value="0">	    			
	    	<img src="http://placehold.it/335x180"/>
	    	<else />	    			
	    	<img src="{$snatch_info.pic|get_cover='path'}"/>
    		</eq>
    	</div>
    	<div class="mui-col-xs-7 join_title_info">
    		<li >{$snatch_info.title}</li>
    		<li>中奖物品：<eq name="snatch_info.prize" value="coin">钻石<else />现金</eq></li>
    	</div>
    </div>
    <div class="time_pay">
	    <div class="time_last">
			<div>剩余支付时间</div>
			<div class="time"></div>
	    </div>
	    <div class="pay_money">
	    	&yen;{$snatch_info.money}元
	    </div>
    </div>
	<div class="float_btn_join">
		<a class="mui-btn" id="btn_sure">立即支付</a>
	</div>
	<div id="popover" class="mui-popover">
		<div class="pop_title">
			<a href="#popover"><span class="mui-icon mui-icon-back"></span></a>请选择支付方式
		</div>
		<ul class="mui-table-view">
	        <li class="mui-table-view-cell">
	            <a class="mui-navigate-right" id="btn_money_pay">
	            	<div class="mui-icon icon-money"></div>
	            	<div class="pay_type_info">余额(<span>{$user_amount}</span>元)</div>
	            </a>
	        </li>
	        <li class="mui-table-view-cell">
	            <a class="mui-navigate-right" id="btn_jtpay_pay">
	            	<div class="mui-icon icon-weixin"></div>
	            	<div class="pay_type_info">微信支付</div>
	            </a>
	        </li>
	        <php>if(is_wechat()){</php>
	        <php>}else{</php>
	        <li class="mui-table-view-cell">
	            <a class="mui-navigate-right" id="btn_alipay_pay">
	            	<div class="mui-icon icon-alipay"></div>
	            	<div class="pay_type_info">支付宝支付</div>
	            </a>
	        </li>
	        <php>}</php>
	    </ul>
	</div>
</block>
<block name="script">
	<script type="text/javascript">
		var intDiff = "{$last_time}",user_code_id = "{$user_code_id}";
		var interval = setInterval(function(){
			var str = '',
				day=0,
		        hour=0,
		        minute=0,
		        second=0;
		    if(intDiff > 0){
		        day = Math.floor(intDiff / (60 * 60 * 24));
		        hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
		        minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
		        second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
		    }
			if(day > 0) str += day + "天";
			if(hour > 0) str += hour + ":";
			if(minute > 0){
				if (minute <= 9) minute = '0' + minute;
				str += minute + ":";
			}else{
				str += "00:";
			}
			if(second > 0){
				if (second <= 9) second = '0' + second;
				str += second;
			}else{
				str += "00";				
			}
			if(intDiff <= 0){
				clearInterval(interval);
				interval = null;
				$(".time").text(str);
				$.post("{:U('snatch/deleteCancelCode')}",{"id":user_code_id},function(result){
					if(result.status == 1){
						mui.alert("支付超时,请重新获取幸运码");
						mui.later(function(){
							location.href="{:U('snatch/getCode',array('id'=>$snatch_info['id']))}";
						},1000)
					}
				},'json');
				$("#btn_sure").addClass("mui-disabled");
			}else{
				$(".time").text(str);
				intDiff--;
			}
		},1000);
		$("#btn_sure").on("click",function(){
			mui('#popover').popover('toggle');
			$("#popover").css('left',((screen.width - $("#popover").width()) / 2) + "px");
			$("#popover").css('top',((screen.height - $("#popover").height()) / 2) + "px");
		});
		$("#btn_money_pay").on('click',function(){
			$.post("{:U('pay')}",{'pay_type':'money','id':user_code_id},function(result){
				if (result.status == 1) {
					location.href = "{:U('pay_success')}";
				}else{
					mui.alert(result.info);
				}
			},'json');
		})
		$("#btn_jtpay_pay").on('click',function(){
			location.href = "{:U('pay',array('pay_type'=>'jtpay','id'=>$user_code_id))}";
		})
		<php>if(is_wechat()){</php>
		<php>}else{</php>
		$("#btn_alipay_pay").on('click',function(){
			location.href = "{:U('pay',array('pay_type'=>'alipay','id'=>$user_code_id))}";
			// $.post("{:U('pay')}",{'pay_type':'alipay','id':user_code_id},function(result){
			// 	console.log(result);
				// if (result.status == 1) {
				// 	location.href = "{:U('pay_success')}";
				// }else{
				// 	mui.alert(result.info);
				// }
			// },'json');
		})
		<php>}</php>
	</script>
</block>
